package com.caocaog.market.controller;

import com.caocaog.market.entity.ShopMemberBind;
import com.caocaog.market.service.ShopMemberBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.GenericController;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺与账号绑定
 *
 * @author chechen
 * @date 2021-12-21
 */
@Slf4j
@RestController
@Api(value = "shopMemberBind", tags = ShopMemberBindController.TABLE_MEANING)
@RequestMapping("/shopMemberBind")
public class ShopMemberBindController extends GenericController<ShopMemberBind, ShopMemberBindService> {

	public static final String TABLE_MEANING = "店铺与账号绑定";

	private static final String BY_ID = "通过店铺id查询";
	@AutoLog(value = BY_ID)
	@ApiOperation(value = BY_ID, notes = BY_ID)
	@GetMapping(value = "/queryByShopId")
	@RequiresPermissions("shopMemberBind:view")
	public Result<?> queryByShopId(@RequestParam(name = "shopId") String shopId) {
		return Result.OK(super.service.queryShopMemberBindByShopId(shopId));
	}

	private static final String ADD = "添加";
	@AutoLog(value = ADD)
	@ApiOperation(value = ADD, notes = ADD)
	@PostMapping(value = "/add/{code}")
	@RequiresPermissions("shopMemberBind:add")
	public Result<?> add(@PathVariable("code") String code, @RequestBody ShopMemberBind shopMemberBind) {
		return Result.OK(ADD_SUCCESS, super.service.addShopMemberBind(code, shopMemberBind));
	}

	private static final String EDIT = "编辑";
	@AutoLog(value = EDIT)
	@ApiOperation(value = EDIT, notes = EDIT)
	@PutMapping(value = "/edit/{code}")
	@RequiresPermissions("shopMemberBind:edit")
	public Result<?> edit(@PathVariable("code") String code, @RequestBody ShopMemberBind shopMemberBind) {
		return Result.OK(EDIT_SUCCESS, super.service.updateShopMemberBind(code, shopMemberBind));
	}

	private static final String UNTIE = "通过shopId解绑";
	@AutoLog(value = UNTIE)
	@ApiOperation(value = UNTIE, notes = UNTIE)
	@DeleteMapping(value = "/untie")
	@RequiresPermissions("shopMemberBind:untie")
	public Result<?> delete(@RequestParam(name = "shopId") String shopId) {
		return Result.OK(DELETE_SUCCESS, super.service.untieShopMemberBind(shopId));
	}

}
